package com.fqy.gmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fqy.gmall.model.user.UserInfo;
import com.fqy.gmall.user.mapper.UserInfoMapper;
import com.fqy.gmall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import sun.security.krb5.internal.crypto.DesCbcMd5EType;

/**
 * User: fqy
 * Date: 2021/9/29
 * Time: 10:06
 * Describe:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //登录：根据用户信息 判断是否能查到此用户
    @Override
    public UserInfo login(UserInfo userInfo) {
        //select * from user_info where login_name = ? passwd = ?
        QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
        userInfoQueryWrapper.eq("login_name",userInfo.getLoginName());
        //  设置密码加密：
        String passwd = userInfo.getPasswd();
        String md5Passwd = DigestUtils.md5DigestAsHex(passwd.getBytes());
        userInfoQueryWrapper.eq("passwd",md5Passwd);
        //  实现类中：可能需要放入缓存，以及生成token 放入cookie 等！
        UserInfo info = userInfoMapper.selectOne(userInfoQueryWrapper);
        return info;
    }
}
